Skip to content

feat(gitlab): Track merge request lifecycle state on PullRequest#118604

Open
malwilley wants to merge 2 commits into
masterfrom
malwilley/gitlab-webhook-docs
Open

feat(gitlab): Track merge request lifecycle state on PullRequest#118604
malwilley wants to merge 2 commits into
masterfrom
malwilley/gitlab-webhook-docs

Conversation

@malwilley

@malwilley malwilley commented Jun 26, 2026

Copy link
Copy Markdown
Member

I've noticed that the PullRequest model, for GitLab PRs, does not have the correct state like it does for the GitHub provider. You can see this redash query which shows that it is always null.

All the information is available in the webhook already, so this creates and updates the PullRequest model with the same information that we give for github.

Motivation: We are relying more on the PullRequest model to display up-to-date PR statuses on the issue, which will not work as expected for gitlab without this change.

Populate the PullRequest lifecycle fields (state, opened_at, closed_at,
merged_at, head_commit_sha, draft) from the GitLab merge request webhook,
mirroring the GitHub integration so the shared PR metrics pipeline has the
same facts for both providers.

GitLab reports the merge request state directly (opened/closed/merged/locked)
and only exposes created_at/updated_at, so closed_at/merged_at are derived
from updated_at based on the state. A merged merge request is treated as
closed as well, matching the GitHub convention where a merged PR has both
closed_at and merged_at set.
Use the merge request's merged_at directly instead of inferring it from
updated_at, and derive closed_at from the lifecycle action rather than the
state. Actions that do not change lifecycle state (e.g. an edit while merged)
leave closed_at untouched via a sentinel, so terminal timestamps no longer
drift to the edit time. head_commit_sha is only written when the event
includes a last commit, preserving the stored value otherwise.
@malwilley malwilley requested a review from a team June 26, 2026 22:25
@malwilley malwilley requested a review from a team as a code owner June 26, 2026 22:25
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 26, 2026
@malwilley malwilley requested a review from scttcper June 26, 2026 22:27
Comment thread src/sentry/integrations/gitlab/webhooks.py

@ceorourke ceorourke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good find

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants